<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>line-height 和 vertical-align 对图片进行垂直居中</title>
  <style>
    #box {
      width: 300px;
      height: 300px;
      background: #ddd;
      line-height: 300px;
    }

    #box img {
      width: 200px;
      height: 200px;
      background-color: #fff;
      vertical-align: middle;
    }
  </style>
</head>

<body>
  <h1>line-height 和 vertical-align 对图片进行垂直居中</h1>
  <p>

  </p>
  <div id="box">
    <img src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png">
  </div>

</body>

</html>